package org.sprong.generagor.domain.entity;

import java.io.IOException;
import java.util.Objects;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author guoqiang.lv 2021/10/18
 */
public class JsoupProxy {

    private String url = "https://www.zdaye.com/dayProxy/ip/332518.html";

    public void parseProxy() throws IOException {
        Document document = Jsoup.connect(url).timeout(20 * 1000).get();
        Elements trs = document.select("#ipc>tobdy>tr");
        for (Element tr : trs) {
            Element ip = tr.selectFirst("td");
            if (Objects.isNull(ip)) {
                continue;
            }
            Element port = ip.nextElementSibling();
            if (Objects.isNull(port)) {
                continue;
            }
            System.out.println(ip.text());
            System.out.println(port.text());
        }
    }

    public static void main(String[] args) throws IOException {
        new JsoupProxy().parseProxy();
    }
}
